<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head th:include="public/page_css::page_css ('修改库位')"/>
<style>
    .layui-form-label {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
</style>
<body>
<div class="layui-fluid larry-wrapper">
    <div class="layui-row layui-col-space30">
        <div class="layui-col-xs24">
            <section class="panel panel-padding">
                <form id="form1" class="layui-form layui-form-pane" action="">
                    <input type="hidden" name="id">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">库位名称</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" lay-verify="required" name="mc" id="mc"
                                       placeholder="请输入库位名称"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">库区名称</label>
                            <div class="layui-input-inline">
                                <select lay-ignore="lay-ignore" class="js-data-example-ajax_sskqid"
                                        lay-verify="required" name="selectId" id="sskqid" select2
                                        style="width: 193px"></select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">可承受重量</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="cszl" id="cszl" placeholder="请输入可承受重量"
                                       lay-verify="zs|validatezs"/>
                            </div>
                            <label style="float: right;margin-top: 10px">kg</label>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">库位托盘数</label>
                            <div class="layui-input-inline">
                                <input type="text" name="tps" id="tps" placeholder="请输入库位托盘数" autocomplete="off"
                                       class="layui-input" lay-verify="number|validateMoney" value="0">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">库位层数</label>
                            <div class="layui-input-inline">
                                <input type="text" name="cs" placeholder="请输入库位层数" autocomplete="off"
                                       class="layui-input"  lay-verify="number|validateMoney">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">可容纳体积</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" name="rntj" id="rntj" placeholder="可容纳体积"
                                       lay-verify="zs|validatezs"/>
                            </div>
                            <label style="float: right;margin-top: 10px">cm³</label>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">拣货顺序</label>
                            <div class="layui-input-inline">
                                <input type="text" name="xlsx" placeholder="请输入拣货顺序" autocomplete="off"
                                       class="layui-input" lay-verify="number|validateMoney"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">库位属性</label>
                            <div class="layui-input-inline">
                                <select name="sx">
                                    <option value="0">正常</option>
                                    <option value="1">封存</option>
                                    <option value="2">管控</option>
                                    <option value="3">禁入</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">库位类型</label>
                            <div class="layui-input-inline">
                                <select name="lx" lay-filter="lxa" disabled>
                                    <option value="0">存储库位</option>
                                    <option value="1">件拣货库位</option>
                                    <option value="2">箱拣货库位</option>
                                    <option value="3">箱/件拣货库位</option>
                                    <option value="4">暂存库位</option>
                                    <option value="5">集货库位</option>
                                    <option value="6">组装工作库位</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-inline">
                                <input type="text" name="bz" placeholder="备注" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">货品混放</label>
                            <div class="layui-input-inline">
                                <select name="hphf" id="hphf" lay-filter="test">
                                    <option value="0">不允许</option>
                                    <option value="1">允许</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">库位高度</label>
                            <div class="layui-input-inline">
                                <input type="text" name="kwgd" placeholder="请输入库位高度" autocomplete="off"
                                       class="layui-input" lay-verify="zs|validatezs"/>
                            </div>
                            <label style="float: right;margin-top: 10px">m</label>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">可用系数</label>
                            <div class="layui-input-inline">
                                <input type="text" name="kyxs" id="kyxs" lay-verify="required|number"
                                       placeholder="请输入库位可用系数" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline" id="div1">
                            <label class="layui-form-label">批次混放</label>
                            <div class="layui-input-inline">
                                <select name="pchf" id="pchf">
                                    <option value="0">不允许</option>
                                    <option value="1">允许</option>
                                </select>
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item" style="float: right;">
                        <div class="layui-input-block">
                            <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="editkuwei">立即提交
                            </button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                    <input type="hidden" th:value="${id}" id="kid">
                </form>
            </section>
        </div>
    </div>
</div>
</body>
<div th:include="public/public_js::public_js"></div>
<script>

    layui.use(['myform', 'zzpUtils', 'form', 'jquery'], function () {
        var form = layui.form,
            zzpUtils = layui.zzpUtils,
            $ = layui.jquery;
        $('.js-data-example-ajax_sskqid').select2({
            ajax: {
                url: '/zxsswms/wmslibraryposition/addSearchArea',
                dataType: 'json',
                type: 'POST',
                contentType: "application/json",
                data: function (params) {
                    var query = {
                        mc: params.term
                    };
                    return JSON.stringify(query);
                },
                processResults: function (data) {
                    var arr = new Array();
                    if (data) {
                        for (var i = 0; i < data.length; i++) {
                            arr.push({id: data[i].id, text: data[i].mc});
                        }
                    }
                    console.log(arr);
                    return {
                        results: arr
                    };
                },
                cache: true
            },
            language: "zh-CN",
            placeholder: '请输入查询库区名称',
            allowClear: true
        });
        var ids = $("#kid").val();
        zzpUtils.action({
            url: "/kuwei/getFind",
            data: JSON.stringify({id: ids}),
            success: function (data) {
                zzpUtils.loadJsonDataToForm(data);
                var sfhf = $("#hphf").val();
                if (sfhf == 0) {
                    $("#div1").show();
                } else if (sfhf == 1) {
                    $("#div1").hide();
                }
            }, error: function (xhr, textStatus) {
                console.log(textStatus);
                console.log(xhr)
            }
        });
        //自定义验证规则-只能输入数字
        form.verify({
            validateMoney: function (value) {
                if (value != '') {
                    if (!/^\d+$/.test(value)) {
                        return '只能填写整数';
                    }
                }
            }
        });
        form.verify({
            validatezs: function (value) {
                if (value != '') {
                    if (!/^\d+(\.{0,1}\d+){0,1}$/.test(value)) {
                        return "请输入非负数";
                    }
                }
            }
        });
        form.on("submit(editkuwei)", function (data) {
            if ($("#kyxs").val() > 1 || $("#kyxs").val() < 0) {
                layer.msg("库位可用系数需在0-1之间");
            } else {
                if($("#hphf").val()==1){
                  console.log(data.field);
                  data.field.pchf=1;
                }
                zzpUtils.confirm("是否确定修改", function (index) {
                    zzpUtils.action({
                        url: "/wmslibraryposition/edit",
                        data: JSON.stringify(data.field),
                        success: function (data) {
                            setTimeout(function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                top.layer.msg(data.title+data.message);
                            }, 500);
                        }, error: function (xhr, textStatus) {
                            console.log(textStatus);
                            console.log(xhr)
                        }
                    })
                })
            }
            return false;

        });
        form.on('select(test)', function (data) {
            if (data.value == 1) {
                $("#div1").hide();
            } else if (data.value == 0) {
                $("#div1").show();
            }
        });
    });
</script>
</html>